<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/jsp/common/common.jsp" %>
</head>
<body>

<div class="documentContent"  id="documentContent">
	<div class="top-div"><em></em><span>&nbsp;>&nbsp;定时任务配置&nbsp;>&nbsp;概要信息</span></div>
	
	<div>
	    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="search-table">
	      <tr>
	        <td style="float: right;">
	        	<button class="btn-table" id="start">启动调度器</button>
	        	<button class="btn-table" id="stop">停止调度器</button>
	        	<button class="btn-table" id="pause">暂停所有任务</button>
	        	<button class="btn-table" id="resume">恢复所有任务</button>
		        <button class="btn-table" id="searchButton">刷新</button>
	        </td>
	      </tr>
	    </table>
	</div>
	
	
	
	<!-- form-box -->
	<div class="form-box">
		<h2 class="form-title">调度器信息<em class="show"></em></h2>
		<div class="form-content">
		 	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="form-table">
		 		<tr>
		 			<td class="form-table-tdleft" width="25%">调度器名称</td>
		 			<td width="25%"><span id="schedulerName_span"></span></td>
		 			<td class="form-table-tdleft" width="25%">开始运行时间</td>
		 			<td width="25%"><span id="runningSince_span"></span></td>
		 		</tr>
		 		<tr>
		 			<td class="form-table-tdleft" width="25%">执行任务数目</td>
		 			<td width="25%"><span id="numJobsExecuted_span"></span></td>
		 			<td class="form-table-tdleft" width="25%">持久化类型</td>
		 			<td width="25%"><span id="persistenceType_span"></span></td>
		 		</tr>
		 		<tr>
		 			<td class="form-table-tdleft" width="25%">线程池数目</td>
		 			<td width="25%"><span id="threadPoolSize_span"></span></td>
		 			<td class="form-table-tdleft" width="25%">版本</td>
		 			<td width="25%"><span id="version_span"></span></td>
		 		</tr>
		 		<tr>
		 			<td class="form-table-tdleft" width="25%">调度器状态</td>
		 			<td width="75%" colspan="3"><span id="state_span"></span></td>
		 		</tr>
		 		<tr>
		 			<td class="form-table-tdleft" width="25%">概要</td>
		 			<td width="75%" colspan="3"><span id="summary_span"></span></td>
		 		</tr>
		 	</table>
		</div>
	</div>
	<!-- form-box -->
	
	<!-- form-box -->
	<div class="form-box">
		<h2 class="form-title">任务列表<em class="show"></em></h2>
		<div class="form-content">
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="form-subtable">
				<thead>
					<tr>
						<th width="20%">名称</th>
						<th width="20%">触发器名称</th>
						<th width="20%">类型名称</th>
						<th width="20%">实际触发时间</th>
						<th width="20%">计划触发时间</th>
					</tr>
				</thead>
				<tbody id="taskTbody"></tbody>
			</table>
		</div>
	</div>
	<!-- form-box -->
	
	
</div>

<script type="text/javascript">
$(document).ready(function(){
	
	getPageData();

	blindPageElement();
	
});

function blindPageElement(){
	$(".form-title").click(function(){
        var b = $(this).parent(".form-box").children(".form-content");
        if(b.css("display") == "block"){
			b.slideUp();
            $(this).children("em").removeClass("show");
            $(this).children("em").addClass("hide");
        }else{
            $(this).children("em").removeClass("hide");
            $(this).children("em").addClass("show");
			b.slideDown();
        }
    });
	
	$('#searchButton').on('click',function(){
		getPageData();
	});
	
    $('#start').on('click',function(){
    	operateScheduler('start');
    });
    
    $('#stop').on('click',function(){
    	operateScheduler('stop');
    });
    
    $('#pause').on('click',function(){
    	operateScheduler('pause');
    });
    
    $('#resume').on('click',function(){
    	operateScheduler('resume');
    });
	
}

function operateScheduler(operate){
	var url = '';
	if(operate == 'start'){
		url = '<%=basePath%>/webframework/scheduler/startScheduler.do';
	}else if(operate == 'stop'){
		url = '<%=basePath%>/webframework/scheduler/shutDownScheduler.do';
	}else if(operate == 'pause'){
		url = '<%=basePath%>/webframework/scheduler/pauseAllSchedulerTask.do';
	}else if(operate == 'resume'){
		url = '<%=basePath%>/webframework/scheduler/resumeAllSchedulerTask.do';
	} 
	
	if(url === ''){
		return;
	}

	$.ajax({  
        url:url,  
        type:'post',  
        dataType:'json',  
        success:function(data,textStatus,jqXHR){
        	if(data.flag && data.flag === 'success'){
	        	showAlert('操作成功');
        	}else{
        		showAlert('操作失败 ->'+data.msg);
        	}
        },  
        error:function(XMLHttpRequest,textStatus,errorThrown){  
        	showAlert('操作错误');
        }                     
    });
}

function getPageData(){
 	var url = '<%=basePath%>/webframework/scheduler/getQuartzData.do';
	$.ajax({  
        url:url,  
        type:'post',  
        dataType:'json',  
        success:function(data,textStatus,jqXHR){  
        	var schedulerInfo = data.data.schedulerInfo;
        	
        	$.each(schedulerInfo,function(key,value){
        		if($('#'+key+'_span')){
        			$('#'+key+'_span').html(value);
        		}
        	});
        	
        	writeTaskTbody(data.gcInfoList);
        },  
        error:function(XMLHttpRequest,textStatus,errorThrown){  
        }                     
    });
	
}

function writeTaskTbody(dataArray){
	
	var targetObject = $('#taskTbody');
	$(targetObject).empty();
	
	$(dataArray).each(function(index,entry){
		
		var trObj = $('<tr></tr>');
		
		$(trObj).append('<td>'+element.name+'</td>');
		$(trObj).append('<td>'+element.triggerName+'</td>');
		$(trObj).append('<td>'+element.groupName+'</td>');
		$(trObj).append('<td>'+element.fireTime+'</td>');
		$(trObj).append('<td>'+element.scheduledFireTime+'</td>');
		
		$(targetObject).append(trObj);
		
	});
	
}



</script>
</body>
</html>